// 记分牌
class ScorePanel {
  score = 0;
  level = 1;
  scoreEl: HTMLElement;
  levelEl: HTMLElement;
  // 设置一个变量限制等级
  maxLevel: number;
  // 设置一个变量表示多少分升级
  upScore: number;
  constructor(maxLevel: number = 10, upScore: number = 10) {
    this.scoreEl = document.querySelector(".score > .num")!;
    this.levelEl = document.querySelector(".level > .num")!;
    this.maxLevel = maxLevel;
    this.upScore = upScore;
  }
  // 设置加分的方法
  addScore(): void {
    // this.score++;
    this.scoreEl.innerText = ++this.score + "";
    // 每 10 分 升一级
    if (this.score % this.upScore === 0) {
      this.levelUp();
    }
  }
  /**
   * 提升等级的方法
   * 等级提升存在上限
   * 等级提升 蛇的速度变快
   */
  levelUp(): void {
    if (this.level < this.maxLevel) {
      this.levelEl.innerText = ++this.level + "";
    }
  }
}
export default ScorePanel;
